package com.zy.mc_module.ui.micang;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.viewbinding.ViewBinding;

import com.zy.mc_module.base.kotlin.BaseActivity;
import com.zy.mc_module.databinding.ActivityRiceDetailBinding;
import com.zy.mc_module.databinding.ActivityRiceIncomeDetailBinding;
import com.zy.mc_module.mvp.bean.PageBean;
import com.zy.mc_module.mvp.bean.RiceDetailBean;
import com.zy.mc_module.mvp.bean.RiceStoreHouseBean;
import com.zy.mc_module.ui.micang.adapter.RiceIncomeDetailAdapter;
import com.zy.mc_module.utils.StatusBarUtil;
import com.zy.mc_module.utils.retrofit.error.ThdException;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * 米粒收支明细
 */
public class RiceIncomeDetailActivity extends BaseActivity<RiceContract.View, RicePresenter, ActivityRiceIncomeDetailBinding> implements RiceContract.View {
    private RiceIncomeDetailAdapter adapter;
    @NonNull
    @Override
    public ActivityRiceIncomeDetailBinding getViewBinding() {
        return ActivityRiceIncomeDetailBinding.inflate(getLayoutInflater());
    }

    @Override
    public void isLoadSir(@NonNull Object... objects) {
        super.isLoadSir(true,binding.refreshLayout.getId());
    }

    @Override
    protected void initView() {
        super.initView();
        StatusBarUtil.setImmersiveStatusBar(this);
        getBinding().customhead.setLeftClickListener(view -> finish());
        initRefresh(binding.refreshLayout,binding.recycleView);
        getBinding().recycleView.setLayoutManager(new LinearLayoutManager(context));
        adapter = new RiceIncomeDetailAdapter(new ArrayList<>());
        getBinding().recycleView.setAdapter(adapter);
        loadData();
    }

    private void loadData() {
        getPresenter().userAccountRecord(context,getPage());
    }

    @Nullable
    @Override
    public RicePresenter createPresenter() {
        return new RicePresenter();
    }

    @Override
    protected void initListener() {
        super.initListener();
    }

    @Override
    public void reloadData() {
        showLoading();
        setPage(1);
        adapter.getList().clear();
        getPresenter().userAccountRecord(getContext(), getPage());
    }

    @Override
    public void refreshData(boolean ReOrLo) {
        getPresenter().userAccountRecord(getContext(), getPage());
    }
    @Override
    public void onError(ThdException error) {

    }

    @Override
    public <T> void onSuccess(T t, int type) {
        if (type == RicePresenter.USER_ACCOUNT_RECORD)
        {
            PageBean<RiceDetailBean> pageBean = (PageBean<RiceDetailBean>) t;
            refreshComplete(pageBean.getList());
            showEmpty(pageBean.getList());
        }
    }

    @Override
    public void onError(ThdException error, int type) {
        showError();
    }
}
